package com.xy.framework.util;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 经纬度算距离
 * 
 * @author Administrator
 *
 */
public class MapDistance {
	private static double EARTH_RADIUS = 5470000;

	private static double rad(double d) {
		return d * Math.PI / 180.0;
	}

	/**
	 * 根据两个位置的经纬度，来计算两地的距离（单位为KM） 参数为String类型
	 * 
	 * @param lat1
	 *            用户经度
	 * @param lng1
	 *            用户纬度
	 * @param lat2
	 *            商家经度
	 * @param lng2
	 *            商家纬度
	 * @return
	 */
	public static String getDistance(String lat1Str, String lng1Str, String lat2Str, String lng2Str) {
		Double lat1 = Double.parseDouble(lat1Str);
		Double lng1 = Double.parseDouble(lng1Str);
		Double lat2 = Double.parseDouble(lat2Str);
		Double lng2 = Double.parseDouble(lng2Str);

		double radLat1 = rad(lat1);
		double radLat2 = rad(lat2);
		double difference = radLat1 - radLat2;
		double mdifference = rad(lng1) - rad(lng2);
		double distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(difference / 2), 2)
				+ Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(mdifference / 2), 2)));
		distance = distance * EARTH_RADIUS;
		distance = Math.round(distance * 10000) / 10000;
		String distanceStr = distance + "";
		distanceStr = distanceStr.substring(0, distanceStr.indexOf("."));

		return distanceStr;
	}

	/**
	 * 获取当前用户一定距离以内的经纬度值 单位米 return minLat 最小经度 minLng 最小纬度 maxLat 最大经度 maxLng
	 * 最大纬度 minLat
	 */
	public static Map getAround(String latStr, String lngStr, String raidus) {
		Map map = new HashMap();

		Double latitude = Double.parseDouble(latStr);// 传值给经度
		Double longitude = Double.parseDouble(lngStr);// 传值给纬度

		Double degree = (24901 * 1609) / 360.0; // 获取每度
		double raidusMile = Double.parseDouble(raidus);

		Double mpdLng = Double.parseDouble((degree * Math.cos(latitude * (Math.PI / 180)) + "").replace("-", ""));
		Double dpmLng = 1 / mpdLng;
		Double radiusLng = dpmLng * raidusMile;
		// 获取最小经度
		Double minLat = longitude - radiusLng;
		// 获取最大经度
		Double maxLat = longitude + radiusLng;

		Double dpmLat = 1 / degree;
		Double radiusLat = dpmLat * raidusMile;
		// 获取最小纬度
		Double minLng = latitude - radiusLat;
		// 获取最大纬度
		Double maxLng = latitude + radiusLat;

		map.put("minLat", minLat + "");
		map.put("maxLat", maxLat + "");
		map.put("minLng", minLng + "");
		map.put("maxLng", maxLng + "");

		return map;
	}

	public static void main(String[] args) {
		// 测试经纬度：117.11811 36.68484
		// 测试经纬度2：117.00999000000002 36.66123
		// System.out.println(getDistance("114.626252","33.581249",
		// "114.132998","33.558196"));

		// System.out.println(getAround("117.11811", "36.68484", "13000"));
		// 117.01028712333508(Double), 117.22593287666493(Double),
		// 36.44829619896034(Double), 36.92138380103966(Double)

		String path = "{\"status\":\"1\",\"info\":\"OK\",\"infocode\":\"10000\",\"count\":\"1\",\"route\":{\"origin\":\"114.132998,33.558196\",\"destination\":\"114.861985,33.498721\",\"taxi_cost\":\"0.0\",\"paths\":[{\"distance\":\"71468\",\"duration\":\"2688\",\"strategy\":\"速度最快\",\"tolls\":\"35\",\"toll_distance\":\"70530\",\"steps\":[{\"instruction\":\"沿G36宁洛高速途径新枯河桥向东行驶70.5千米向右前方行驶进入匝道\",\"orientation\":\"东\",\"road\":\"G36宁洛高速\",\"distance\":\"70530\",\"tolls\":\"35\",\"toll_distance\":\"70530\",\"toll_road\":\"G36宁洛高速\",\"duration\":\"2575\",\"polyline\":\"114.132996,33.558201;114.133888,33.558357;114.135117,33.558605;114.136459,33.558903;114.137802,33.559227;114.139076,33.55957;114.141197,33.560177;114.142403,33.56057;114.143394,33.560905;114.145378,33.56163;114.146568,33.562107;114.147949,33.562683;114.148079,33.562737;114.148903,33.563114;114.149147,33.563229;114.151451,33.564312;114.155464,33.566433;114.156311,33.566845;114.159439,33.568321;114.161331,33.569141;114.162521,33.569614;114.164101,33.570213;114.165916,33.570869;114.167664,33.571449;114.169182,33.571926;114.169922,33.572136;114.171272,33.572521;114.172943,33.57296;114.174347,33.573311;114.175468,33.573563;114.177399,33.573963;114.178726,33.574207;114.178764,33.574219;114.179619,33.574364;114.182297,33.574772;114.191895,33.576077;114.207314,33.57819;114.208221,33.578327;114.211739,33.578793;114.213867,33.57909;114.225334,33.580662;114.228416,33.581055;114.230927,33.581326;114.234001,33.581539;114.23584,33.581631;114.236389,33.581654;114.238998,33.581703;114.240868,33.581688;114.242607,33.581646;114.244469,33.58157;114.245293,33.581524;114.246513,33.58144;114.248444,33.58128;114.249832,33.581142;114.255692,33.580463;114.256638,33.580353;114.257812,33.580223;114.265709,33.579308;114.273819,33.578369;114.279785,33.577682;114.282486,33.577374;114.286674,33.576893;114.287605,33.576794;114.289825,33.576591;114.294258,33.576302;114.297363,33.576187;114.299164,33.576164;114.301758,33.576176;114.302658,33.57618;114.30584,33.576275;114.308952,33.576454;114.311256,33.576614;114.316765,33.577061;114.319817,33.577297;114.322998,33.577553;114.323647,33.577599;114.323723,33.57761;114.324303,33.577656;114.330612,33.578163;114.332268,33.57827;114.332993,33.578323;114.338448,33.578781;114.341415,33.579002;114.344055,33.579308;114.345703,33.579533;114.346069,33.579578;114.348053,33.57991;114.350464,33.580364;114.352348,33.580784;114.353508,33.581066;114.35601,33.58173;114.356812,33.581936;114.357559,33.582165;114.36039,33.583099;114.361961,33.583656;114.363647,33.584301;114.365929,33.585205;114.367668,33.585884;114.371635,33.587437;114.373146,33.587986;114.374374,33.588406;114.37619,33.588974;114.377701,33.589405;114.3787,33.589672;114.380074,33.590008;114.380821,33.590183;114.381683,33.59037;114.38353,33.590729;114.385468,33.591053;114.386818,33.591244;114.388161,33.591412;114.389366,33.591534;114.389641,33.591568;114.391678,33.591721;114.393188,33.591805;114.395882,33.591854;114.397369,33.591862;114.399117,33.591801;114.401001,33.591686;114.403549,33.591454;114.4048,33.591316;114.411621,33.590534;114.415001,33.59016;114.421463,33.589409;114.42289,33.589218;114.425194,33.588982;114.433594,33.588009;114.434547,33.58791;114.435852,33.587795;114.438042,33.587646;114.440865,33.587555;114.442032,33.587547;114.443901,33.587563;114.445122,33.587612;114.446564,33.587677;114.44854,33.587822;114.449402,33.587894;114.450935,33.588066;114.45211,33.588207;114.453117,33.588348;114.455086,33.588657;114.455566,33.588753;114.45562,33.588757;114.457512,33.589115;114.458572,33.589344;114.477539,33.593651;114.478027,33.593761;114.481728,33.594578;114.483665,33.594963;114.485306,33.595238;114.486763,33.595448;114.487114,33.595512;114.489388,33.595848;114.4916,33.596104;114.492348,33.596172;114.492523,33.596188;114.494118,33.596329;114.495972,33.596466;114.497223,33.596535;114.49839,33.596577;114.499512,33.5966;114.500282,33.596615;114.501015,33.596645;114.502464,33.596706;114.505562,33.596802;114.508171,33.596874;114.509056,33.596909;114.509689,33.596924;114.521484,33.597294;114.52597,33.597431;114.528587,33.597462;114.531128,33.597424;114.532951,33.597366;114.534454,33.597301;114.538124,33.597054;114.541359,33.596737;114.543068,33.596535;114.543457,33.596481;114.544434,33.596348;114.545456,33.596188;114.546478,33.596039;114.549759,33.595478;114.551254,33.595181;114.55275,33.594868;114.55365,33.594669;114.555031,33.594349;114.557785,33.593658;114.56543,33.591557;114.56601,33.591396;114.57135,33.589901;114.580353,33.587437;114.587402,33.585522;114.58857,33.585205;114.590912,33.584568;114.59304,33.584026;114.59465,33.583641;114.596504,33.583229;114.599022,33.582729;114.601921,33.582214;114.603683,33.581947;114.605698,33.581665;114.609375,33.581245;114.609467,33.581234;114.618355,33.580154;114.620705,33.579891;114.62149,33.579796;114.622292,33.579704;114.62442,33.579453;114.62587,33.579285;114.626602,33.579193;114.627632,33.579071;114.630325,33.578754;114.63134,33.578632;114.631851,33.578571;114.640648,33.577526;114.645714,33.57692;114.646576,33.576805;114.64817,33.576565;114.649193,33.576393;114.650719,33.576092;114.652962,33.575596;114.653328,33.575504;114.654457,33.575226;114.65583,33.574844;114.656944,33.574528;114.657814,33.574253;114.657936,33.574219;114.659172,33.573814;114.660545,33.573338;114.662277,33.572681;114.663528,33.572166;114.664124,33.571915;114.666496,33.570866;114.670105,33.56926;114.670845,33.568928;114.671761,33.568542;114.673607,33.567787;114.674446,33.567471;114.675285,33.567158;114.676033,33.566895;114.676826,33.566616;114.6791,33.565884;114.680107,33.56559;114.682297,33.564972;114.683411,33.564701;114.683914,33.564571;114.684464,33.564445;114.685585,33.564198;114.687958,33.563709;114.690712,33.563229;114.692062,33.563;114.693665,33.562721;114.697266,33.562092;114.698433,33.561893;114.701935,33.561253;114.703003,33.561035;114.7043,33.560707;114.705193,33.560459;114.706703,33.55999;114.708054,33.559494;114.709442,33.558945;114.711372,33.55798;114.712112,33.557568;114.71386,33.556534;114.719238,33.553108;114.719421,33.55299;114.720154,33.552544;114.720558,33.552307;114.720673,33.552246;114.721558,33.551788;114.721909,33.551617;114.722679,33.551285;114.723495,33.550968;114.724197,33.550739;114.725037,33.550495;114.725807,33.550304;114.726479,33.550167;114.727058,33.550064;114.72847,33.549896;114.729263,33.549839;114.729744,33.549828;114.730812,33.549816;114.731491,33.549831;114.739227,33.550083;114.740585,33.550114;114.741211,33.550114;114.741669,33.550114;114.742569,33.550091;114.74321,33.550056;114.744865,33.549908;114.745628,33.549816;114.746964,33.549614;114.748314,33.549335;114.748978,33.549171;114.750114,33.54887;114.750679,33.548702;114.752197,33.548183;114.753296,33.547741;114.754425,33.547249;114.755386,33.54681;114.755524,33.546745;114.757339,33.545876;114.761566,33.543877;114.763184,33.543106;114.764114,33.542664;114.765411,33.542076;114.766579,33.541588;114.767433,33.541256;114.767929,33.541065;114.769096,33.540646;114.7705,33.540192;114.771866,33.539787;114.773598,33.539345;114.77446,33.539143;114.775681,33.538883;114.777336,33.538582;114.785156,33.537197;114.788696,33.536575;114.790596,33.536224;114.791794,33.53598;114.792686,33.535778;114.7939,33.53545;114.7957,33.534904;114.796349,33.534679;114.796898,33.53447;114.798668,33.533756;114.800125,33.533081;114.801537,33.532337;114.802597,33.531723;114.80349,33.531166;114.804092,33.530754;114.804665,33.53035;114.804779,33.530273;114.805664,33.52961;114.806488,33.528942;114.807129,33.528389;114.80722,33.528301;114.808098,33.527493;114.808914,33.526688;114.810646,33.524899;114.810806,33.524738;114.811111,33.524437;114.812927,33.522598;114.814232,33.521263;114.816177,33.519283;114.818314,33.517128;114.819199,33.516277;114.820442,33.515121;114.821686,33.514072;114.823143,33.51289;114.824074,33.51218;114.825165,33.511383;114.825928,33.510841;114.826775,33.510254;114.828178,33.509346;114.829102,33.508781;114.829887,33.508297;114.830383,33.507999;114.832047,33.507057;114.832954,33.50658;114.835434,33.505337;114.836891,33.504662;114.83918,33.503689;114.841408,33.502819;114.842018,33.502594;114.847977,33.50061;114.851074,33.499546;114.851608,33.499363;114.854156,33.498486\",\"action\":\"向右前方行驶\",\"assistant_action\":\"进入匝道\",\"tmcs\":[{\"lcode\":[],\"distance\":\"11826\",\"status\":\"畅通\",\"polyline\":\"114.132996,33.558201;114.133888,33.558357;114.135117,33.558605;114.136459,33.558903;114.137802,33.559227;114.139076,33.55957;114.141197,33.560177;114.142403,33.56057;114.143394,33.560905;114.145378,33.56163;114.146568,33.562107;114.147949,33.562683;114.148079,33.562737;114.148903,33.563114;114.149147,33.563229;114.151451,33.564312;114.155464,33.566433;114.156311,33.566845;114.159439,33.568321;114.161331,33.569141;114.162521,33.569614;114.164101,33.570213;114.165916,33.570869;114.167664,33.571449;114.169182,33.571926;114.169922,33.572136;114.171272,33.572521;114.172943,33.57296;114.174347,33.573311;114.175468,33.573563;114.177399,33.573963;114.178726,33.574207;114.178764,33.574219;114.179619,33.574364;114.182297,33.574772;114.191895,33.576077;114.207314,33.57819;114.208221,33.578327;114.211739,33.578793;114.213867,33.57909;114.225334,33.580662;114.228416,33.581055;114.230927,33.581326;114.234001,33.581539;114.23584,33.581631;114.236389,33.581654;114.238998,33.581703;114.240868,33.581688;114.242607,33.581646;114.244469,33.58157;114.245293,33.581524;114.246513,33.58144;114.248444,33.58128;114.249832,33.581142;114.255692,33.580463\"},{\"lcode\":[],\"distance\":\"1699\",\"status\":\"畅通\",\"polyline\":\"114.255692,33.580463;114.256638,33.580353;114.257812,33.580223;114.265709,33.579308;114.273819,33.578369\"},{\"lcode\":[],\"distance\":\"4008\",\"status\":\"畅通\",\"polyline\":\"114.273819,33.578369;114.279785,33.577682;114.282486,33.577374;114.286674,33.576893;114.287605,33.576794;114.289825,33.576591;114.294258,33.576302;114.297363,33.576187;114.299164,33.576164;114.301758,33.576176;114.302658,33.57618;114.30584,33.576275;114.308952,33.576454;114.311256,33.576614;114.316765,33.577061\"},{\"lcode\":[],\"distance\":\"580\",\"status\":\"畅通\",\"polyline\":\"114.316765,33.577061;114.319817,33.577297;114.322998,33.577553\"},{\"lcode\":[],\"distance\":\"122\",\"status\":\"畅通\",\"polyline\":\"114.322998,33.577553;114.323647,33.577599;114.323723,33.57761;114.324303,33.577656\"},{\"lcode\":[],\"distance\":\"3065\",\"status\":\"畅通\",\"polyline\":\"114.324303,33.577656;114.330612,33.578163;114.332268,33.57827;114.332993,33.578323;114.338448,33.578781;114.341415,33.579002;114.344055,33.579308;114.345703,33.579533;114.346069,33.579578;114.348053,33.57991;114.350464,33.580364;114.352348,33.580784;114.353508,33.581066;114.35601,33.58173;114.356812,33.581936\"},{\"lcode\":[],\"distance\":\"2413\",\"status\":\"畅通\",\"polyline\":\"114.356812,33.581936;114.357559,33.582165;114.36039,33.583099;114.361961,33.583656;114.363647,33.584301;114.365929,33.585205;114.367668,33.585884;114.371635,33.587437;114.373146,33.587986;114.374374,33.588406;114.37619,33.588974;114.377701,33.589405;114.3787,33.589672;114.380074,33.590008;114.380821,33.590183\"},{\"lcode\":[],\"distance\":\"5904\",\"status\":\"畅通\",\"polyline\":\"114.380821,33.590183;114.381683,33.59037;114.38353,33.590729;114.385468,33.591053;114.386818,33.591244;114.388161,33.591412;114.389366,33.591534;114.389641,33.591568;114.391678,33.591721;114.393188,33.591805;114.395882,33.591854;114.397369,33.591862;114.399117,33.591801;114.401001,33.591686;114.403549,33.591454;114.4048,33.591316;114.411621,33.590534;114.415001,33.59016;114.421463,33.589409;114.42289,33.589218;114.425194,33.588982;114.433594,33.588009;114.434547,33.58791;114.435852,33.587795;114.438042,33.587646;114.440865,33.587555;114.442032,33.587547;114.443901,33.587563\"},{\"lcode\":[],\"distance\":\"247\",\"status\":\"畅通\",\"polyline\":\"114.443901,33.587563;114.445122,33.587612;114.446564,33.587677\"},{\"lcode\":[],\"distance\":\"4525\",\"status\":\"畅通\",\"polyline\":\"114.446564,33.587677;114.44854,33.587822;114.449402,33.587894;114.450935,33.588066;114.45211,33.588207;114.453117,33.588348;114.455086,33.588657;114.455566,33.588753;114.45562,33.588757;114.457512,33.589115;114.458572,33.589344;114.477539,33.593651;114.478027,33.593761;114.481728,33.594578;114.483665,33.594963;114.485306,33.595238;114.486763,33.595448;114.487114,33.595512;114.489388,33.595848;114.4916,33.596104;114.492348,33.596172;114.492523,33.596188;114.494118,33.596329\"},{\"lcode\":[],\"distance\":\"290\",\"status\":\"畅通\",\"polyline\":\"114.494118,33.596329;114.495972,33.596466;114.497223,33.596535\"},{\"lcode\":[],\"distance\":\"486\",\"status\":\"畅通\",\"polyline\":\"114.497223,33.596535;114.49839,33.596577;114.499512,33.5966;114.500282,33.596615;114.501015,33.596645;114.502464,33.596706\"},{\"lcode\":[],\"distance\":\"287\",\"status\":\"畅通\",\"polyline\":\"114.502464,33.596706;114.505562,33.596802\"},{\"lcode\":[],\"distance\":\"242\",\"status\":\"畅通\",\"polyline\":\"114.505562,33.596802;114.508171,33.596874\"},{\"lcode\":[],\"distance\":\"82\",\"status\":\"畅通\",\"polyline\":\"114.508171,33.596874;114.509056,33.596909\"},{\"lcode\":[],\"distance\":\"9217\",\"status\":\"畅通\",\"polyline\":\"114.509056,33.596909;114.509689,33.596924;114.521484,33.597294;114.52597,33.597431;114.528587,33.597462;114.531128,33.597424;114.532951,33.597366;114.534454,33.597301;114.538124,33.597054;114.541359,33.596737;114.543068,33.596535;114.543457,33.596481;114.544434,33.596348;114.545456,33.596188;114.546478,33.596039;114.549759,33.595478;114.551254,33.595181;114.55275,33.594868;114.55365,33.594669;114.555031,33.594349;114.557785,33.593658;114.56543,33.591557;114.56601,33.591396;114.57135,33.589901;114.580353,33.587437;114.587402,33.585522;114.58857,33.585205;114.590912,33.584568;114.59304,33.584026;114.59465,33.583641;114.596504,33.583229;114.599022,33.582729;114.601921,33.582214;114.603683,33.581947;114.605698,33.581665\"},{\"lcode\":[],\"distance\":\"1187\",\"status\":\"畅通\",\"polyline\":\"114.605698,33.581665;114.609375,33.581245;114.609467,33.581234;114.618355,33.580154\"},{\"lcode\":[],\"distance\":\"219\",\"status\":\"畅通\",\"polyline\":\"114.618355,33.580154;114.620705,33.579891\"},{\"lcode\":[],\"distance\":\"150\",\"status\":\"畅通\",\"polyline\":\"114.620705,33.579891;114.62149,33.579796;114.622292,33.579704\"},{\"lcode\":[],\"distance\":\"334\",\"status\":\"畅通\",\"polyline\":\"114.622292,33.579704;114.62442,33.579453;114.62587,33.579285\"},{\"lcode\":[],\"distance\":\"165\",\"status\":\"畅通\",\"polyline\":\"114.62587,33.579285;114.626602,33.579193;114.627632,33.579071\"},{\"lcode\":[],\"distance\":\"253\",\"status\":\"畅通\",\"polyline\":\"114.627632,33.579071;114.630325,33.578754\"},{\"lcode\":[],\"distance\":\"142\",\"status\":\"畅通\",\"polyline\":\"114.630325,33.578754;114.63134,33.578632;114.631851,33.578571\"},{\"lcode\":[],\"distance\":\"3734\",\"status\":\"畅通\",\"polyline\":\"114.631851,33.578571;114.640648,33.577526;114.645714,33.57692;114.646576,33.576805;114.64817,33.576565;114.649193,33.576393;114.650719,33.576092;114.652962,33.575596;114.653328,33.575504;114.654457,33.575226;114.65583,33.574844;114.656944,33.574528;114.657814,33.574253;114.657936,33.574219;114.659172,33.573814;114.660545,33.573338;114.662277,33.572681;114.663528,33.572166;114.664124,33.571915;114.666496,33.570866;114.670105,33.56926\"},{\"lcode\":[],\"distance\":\"610\",\"status\":\"畅通\",\"polyline\":\"114.670105,33.56926;114.670845,33.568928;114.671761,33.568542;114.673607,33.567787;114.674446,33.567471;114.675285,33.567158;114.676033,33.566895\"},{\"lcode\":[],\"distance\":\"79\",\"status\":\"畅通\",\"polyline\":\"114.676033,33.566895;114.676826,33.566616\"},{\"lcode\":[],\"distance\":\"648\",\"status\":\"畅通\",\"polyline\":\"114.676826,33.566616;114.6791,33.565884;114.680107,33.56559;114.682297,33.564972;114.683411,33.564701\"},{\"lcode\":[],\"distance\":\"48\",\"status\":\"畅通\",\"polyline\":\"114.683411,33.564701;114.683914,33.564571\"},{\"lcode\":[],\"distance\":\"52\",\"status\":\"畅通\",\"polyline\":\"114.683914,33.564571;114.684464,33.564445\"},{\"lcode\":[],\"distance\":\"875\",\"status\":\"畅通\",\"polyline\":\"114.684464,33.564445;114.685585,33.564198;114.687958,33.563709;114.690712,33.563229;114.692062,33.563;114.693665,33.562721\"},{\"lcode\":[],\"distance\":\"452\",\"status\":\"畅通\",\"polyline\":\"114.693665,33.562721;114.697266,33.562092;114.698433,33.561893\"},{\"lcode\":[],\"distance\":\"5703\",\"status\":\"畅通\",\"polyline\":\"114.698433,33.561893;114.701935,33.561253;114.703003,33.561035;114.7043,33.560707;114.705193,33.560459;114.706703,33.55999;114.708054,33.559494;114.709442,33.558945;114.711372,33.55798;114.712112,33.557568;114.71386,33.556534;114.719238,33.553108;114.719421,33.55299;114.720154,33.552544;114.720558,33.552307;114.720673,33.552246;114.721558,33.551788;114.721909,33.551617;114.722679,33.551285;114.723495,33.550968;114.724197,33.550739;114.725037,33.550495;114.725807,33.550304;114.726479,33.550167;114.727058,33.550064;114.72847,33.549896;114.729263,33.549839;114.729744,33.549828;114.730812,33.549816;114.731491,33.549831;114.739227,33.550083;114.740585,33.550114;114.741211,33.550114;114.741669,33.550114;114.742569,33.550091;114.74321,33.550056;114.744865,33.549908;114.745628,33.549816;114.746964,33.549614;114.748314,33.549335;114.748978,33.549171;114.750114,33.54887;114.750679,33.548702;114.752197,33.548183;114.753296,33.547741;114.754425,33.547249;114.755386,33.54681\"},{\"lcode\":[],\"distance\":\"14\",\"status\":\"畅通\",\"polyline\":\"114.755386,33.54681;114.755524,33.546745\"},{\"lcode\":[],\"distance\":\"194\",\"status\":\"畅通\",\"polyline\":\"114.755524,33.546745;114.757339,33.545876\"},{\"lcode\":[],\"distance\":\"4096\",\"status\":\"畅通\",\"polyline\":\"114.757339,33.545876;114.761566,33.543877;114.763184,33.543106;114.764114,33.542664;114.765411,33.542076;114.766579,33.541588;114.767433,33.541256;114.767929,33.541065;114.769096,33.540646;114.7705,33.540192;114.771866,33.539787;114.773598,33.539345;114.77446,33.539143;114.775681,33.538883;114.777336,33.538582;114.785156,33.537197;114.788696,33.536575;114.790596,33.536224;114.791794,33.53598;114.792686,33.535778;114.7939,33.53545;114.7957,33.534904;114.796349,33.534679;114.796898,33.53447;114.798668,33.533756\"},{\"lcode\":[],\"distance\":\"310\",\"status\":\"畅通\",\"polyline\":\"114.798668,33.533756;114.800125,33.533081;114.801537,33.532337\"},{\"lcode\":[],\"distance\":\"294\",\"status\":\"畅通\",\"polyline\":\"114.801537,33.532337;114.802597,33.531723;114.80349,33.531166;114.804092,33.530754\"},{\"lcode\":[],\"distance\":\"892\",\"status\":\"畅通\",\"polyline\":\"114.804092,33.530754;114.804665,33.53035;114.804779,33.530273;114.805664,33.52961;114.806488,33.528942;114.807129,33.528389;114.80722,33.528301;114.808098,33.527493;114.808914,33.526688;114.810646,33.524899\"},{\"lcode\":[],\"distance\":\"22\",\"status\":\"畅通\",\"polyline\":\"114.810646,33.524899;114.810806,33.524738\"},{\"lcode\":[],\"distance\":\"44\",\"status\":\"畅通\",\"polyline\":\"114.810806,33.524738;114.811111,33.524437\"},{\"lcode\":[],\"distance\":\"264\",\"status\":\"畅通\",\"polyline\":\"114.811111,33.524437;114.812927,33.522598\"},{\"lcode\":[],\"distance\":\"4756\",\"status\":\"畅通\",\"polyline\":\"114.812927,33.522598;114.814232,33.521263;114.816177,33.519283;114.818314,33.517128;114.819199,33.516277;114.820442,33.515121;114.821686,33.514072;114.823143,33.51289;114.824074,33.51218;114.825165,33.511383;114.825928,33.510841;114.826775,33.510254;114.828178,33.509346;114.829102,33.508781;114.829887,33.508297;114.830383,33.507999;114.832047,33.507057;114.832954,33.50658;114.835434,33.505337;114.836891,33.504662;114.83918,33.503689;114.841408,33.502819;114.842018,33.502594;114.847977,33.50061;114.851074,33.499546;114.851608,33.499363;114.854156,33.498486\"}],\"cities\":[{\"name\":\"漯河市\",\"citycode\":\"0395\",\"adcode\":\"411100\",\"districts\":[{\"name\":\"召陵区\",\"adcode\":\"411104\"}]},{\"name\":\"周口市\",\"citycode\":\"0394\",\"adcode\":\"411600\",\"districts\":[{\"name\":\"商水县\",\"adcode\":\"411623\"},{\"name\":\"川汇区\",\"adcode\":\"411602\"}]}]},{\"instruction\":\"沿G36宁洛高速出口向东行驶938米到达目的地\",\"orientation\":\"东\",\"road\":\"G36宁洛高速出口\",\"distance\":\"938\",\"tolls\":\"0\",\"toll_distance\":\"0\",\"toll_road\":[],\"duration\":\"113\",\"polyline\":\"114.854156,33.498486;114.854309,33.498425;114.85463,33.498302;114.854996,33.498077;114.855057,33.498043;114.855194,33.497971;114.855324,33.49789;114.855423,33.497814;114.855545,33.4977;114.855682,33.497547;114.855804,33.497364;114.855843,33.497314;114.855896,33.497219;114.855934,33.497108;114.856064,33.496815;114.856171,33.496574;114.856216,33.496502;114.856293,33.496395;114.856377,33.496323;114.856491,33.496246;114.856567,33.496212;114.856682,33.496166;114.856796,33.496155;114.856918,33.496151;114.857033,33.496155;114.857147,33.496174;114.857307,33.49622;114.85743,33.496265;114.857597,33.496346;114.857941,33.496529;114.859344,33.497314;114.860123,33.497746;114.860443,33.497925;114.860916,33.49815;114.861084,33.498226;114.861282,33.498299;114.86161,33.498451;114.862015,33.498672\",\"action\":[],\"assistant_action\":\"到达目的地\",\"tmcs\":[{\"lcode\":[],\"distance\":\"48\",\"status\":\"畅通\",\"polyline\":\"114.854156,33.498486;114.854309,33.498425;114.85463,33.498302\"},{\"lcode\":[],\"distance\":\"772\",\"status\":\"畅通\",\"polyline\":\"114.85463,33.498302;114.854996,33.498077;114.855057,33.498043;114.855194,33.497971;114.855324,33.49789;114.855423,33.497814;114.855545,33.4977;114.855682,33.497547;114.855804,33.497364;114.855843,33.497314;114.855896,33.497219;114.855934,33.497108;114.856064,33.496815;114.856171,33.496574;114.856216,33.496502;114.856293,33.496395;114.856377,33.496323;114.856491,33.496246;114.856567,33.496212;114.856682,33.496166;114.856796,33.496155;114.856918,33.496151;114.857033,33.496155;114.857147,33.496174;114.857307,33.49622;114.85743,33.496265;114.857597,33.496346;114.857941,33.496529;114.859344,33.497314;114.860123,33.497746;114.860443,33.497925;114.860916,33.49815\"},{\"lcode\":[],\"distance\":\"37\",\"status\":\"畅通\",\"polyline\":\"114.860916,33.49815;114.861084,33.498226;114.861282,33.498299\"},{\"lcode\":[],\"distance\":\"81\",\"status\":\"畅通\",\"polyline\":\"114.861282,33.498299;114.86161,33.498451;114.862015,33.498672\"}],\"cities\":[{\"name\":\"周口市\",\"citycode\":\"0394\",\"adcode\":\"411600\",\"districts\":[{\"name\":\"商水县\",\"adcode\":\"411623\"}]}]}],\"restriction\":\"0\",\"traffic_lights\":\"0\"}]}}";
		JSONObject jsonObject = (JSONObject) JSON.parse(path);

		JSONObject route = (JSONObject) JSON.parse(jsonObject.get("route").toString());
		JSONArray paths = (JSONArray) JSON.parse(route.get("paths").toString());
		JSONObject steps = (JSONObject) JSON.parse(paths.get(0).toString());
		JSONArray stepsss = (JSONArray) JSON.parse(steps.get("steps").toString());
		Map<String, String> map = new HashMap<>();
		String lat1 = "";
		String lng1 = "";
		String lat2 = "";
		String lng2 = "";
		double j = 0;
		for (int i = 0; i < stepsss.size(); i++) {
			JSONObject polyline = (JSONObject) JSON.parse(stepsss.get(i).toString());
			String[] polylines = polyline.get("polyline").toString().split(";");
			for (String string : polylines) {
				map.put(string.split(",")[0], string.split(",")[1]);
				lat2 = lat1;
				lng2 = lng1;
				lat1 = string.split(",")[0];
				lng1 = string.split(",")[1];
				if (!lat2.equals("")) {
					double d = Double.parseDouble(getDistance(lat1, lng1, lat2, lng2));
					System.out.println(d);
					j = j + d;
				}
			}
		}
		System.out.println(j);
		/*
		 * Map map2 =(Map) map.get("route"); Map paths =(Map) map2.get("paths");
		 * Map paths0 =(Map) paths.get("0"); Map steps =(Map)
		 * paths0.get("steps");
		 */

	}

}
